//
//  BYMineInfoOrderCell.m
//  OCDemo
//
//  Created by 朱慕之 on 2022/1/5.
//

#import "BYMineInfoOrderCell.h"

#define MineInfoBackGroundImage    [UIImage imageNamed:@"mine_backImage"]

@interface BYMineInfoOrderCell ()

@property (nonatomic, strong) UIImageView       *backGroundView;

@property (nonatomic, strong) BYMineInfoView    *infoView;

@property (nonatomic, strong) BYMineOrderView   *orderView;

@end


@implementation BYMineInfoOrderCell

#pragma mark - SetData
- (void)setData {
    [self.infoView setData];
}

#pragma mark - Init

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self.contentView addSubview:self.backGroundView];
        [self.contentView addSubview:self.infoView];
        [self.contentView addSubview:self.orderView];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.backGroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.contentView);
        make.height.equalTo(@(kAutoWithSize(MineInfoBackGroundImage.size.height)));
    }];
    
    [self.infoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.contentView).offset(kAutoWithSize(44.0f));
        make.height.equalTo(@(kAutoWithSize(80)));
    }];
    
    [self.orderView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.contentView);
        make.top.equalTo(self.infoView.mas_bottom).offset(kAutoWithSize(10.0));
        make.bottom.equalTo(self.contentView);
    }];
}


#pragma mark - CellHeight

+ (CGFloat)cellHeight {
    if([AppConfig isAdministrator]){
        return kAutoWithSize(MineInfoBackGroundImage.size.height)+kAutoWithSize(80);
    }
    return kAutoWithSize(MineInfoBackGroundImage.size.height)+kAutoWithSize(160);
}


#pragma mark - LazyGet

- (UIImageView *)backGroundView {
    if (!_backGroundView) {
        _backGroundView = [[UIImageView alloc] init];
        _backGroundView.image = MineInfoBackGroundImage;
    }
    return _backGroundView;
}

- (BYMineInfoView *)infoView {
    if(!_infoView) {
        _infoView = [[BYMineInfoView alloc] init];
        WS(weakSelf)
        
        _infoView.signinBlock = ^{
            if (weakSelf.signinBlock) {
                weakSelf.signinBlock();
            }
        };
        
        _infoView.loginBlock = ^{
            if (weakSelf.loginBlock) {
                weakSelf.loginBlock();
            }
        };        
    }
    return _infoView;
}

- (BYMineOrderView *)orderView {
    if (!_orderView) {
        _orderView = [[BYMineOrderView alloc] init];
        _orderView.orderItemBlock = ^(NSString * _Nonnull title) {
            NSLog(@"orderItemBlock:%@", title);
        };
        _orderView.allOrderBlock = ^(NSString * _Nonnull title) {
            NSLog(@"allOrderBlock:%@", title);
        };
    }
    return _orderView;
}



@end
